package cn.haohaowo.config;

import org.apache.kafka.clients.producer.RecordMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.support.ProducerListenerAdapter;
import org.springframework.stereotype.Component;

/**
 * Created by luwancai on 18/4/16.
 * DESC:
 */
@Component
public class ProducerMessageListener extends ProducerListenerAdapter {

    private static final Logger log = LoggerFactory.getLogger(ProducerMessageListener.class);

    @Override
    public void onSuccess(String topic, Integer partition, Object key, Object value, RecordMetadata recordMetadata) {
        super.onSuccess(topic, partition, key, value, recordMetadata);
        log.info("Is success, topic: {},  partition: {}, key: {}, value: {}, recordMetadata: {}",
                topic, partition, key, value.toString(), recordMetadata.toString());
    }

    @Override
    public void onError(String topic, Integer partition, Object key, Object value, Exception exception) {
        super.onError(topic, partition, key, value, exception);
        log.info("Is error , topic: {},  partition: {}, key: {}, value: {}, exception: {}",
                topic, partition, key, value.toString(), exception.getMessage());
        exception.printStackTrace();
    }

    @Override
    public boolean isInterestedInSuccess() {
        return true;
    }
}
